/**
 * @version Create on 2012-10-30
 * @author Yinzi Chen
 */

public class BestTimeToStock {

	public int maxProfit(int[] prices) {
		int n = prices.length;
		if (n == 0)
			return 0;
		int max = 0;
		int p = prices[0];
		for (int i = 1; i < n; ++i) {
			max = Math.max(prices[i] - p, max);
			p = Math.min(p, prices[i]);
		}
		return max;
	}

	public static void main(String[] args) {

	}

}
